<template>
  <div class="app-container" v-loading="loading">
    <el-form
        ref="queryRef"
        :inline="true"
        :model="queryParams"
        class="form-box"
    >
      <div style="display: flex;flex-wrap: wrap">
        <el-col :span="4">
          <el-form-item>
            <el-input
                v-model="queryParams.purchaseCode"
                clearable
                placeholder="采购单号"
            />
          </el-form-item>
        </el-col>

        <el-col :span="4">
          <el-form-item>
            <el-select
                clearable
                placeholder="退货状态"
                v-model="queryParams.status"
            >
              <template v-for="(item,index) in erp_qc_return_status" :key="index">
                <el-option :label="item.label" :value="item.value"></el-option>
              </template>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="4">
          <el-form-item>
            <el-input
                v-model="queryParams.skuCode"
                clearable
                placeholder="SKU编码"

            />
          </el-form-item>
        </el-col>

        <el-col :span="4">
          <el-form-item>
            <el-input
                v-model="queryParams.skuName"
                clearable
                placeholder="商品名称"

            />
          </el-form-item>
        </el-col>

        <el-col :span="4">
          <el-form-item>
            <el-input
                v-model="queryParams.qcByName"
                clearable
                placeholder="质检人"

            />
          </el-form-item>
        </el-col>

        <el-col :span="4">
          <el-form-item class="picker">
            <el-date-picker
                style="width:100%"
                v-model="timeData"
                start-placeholder="质检时间"
                end-placeholder="质检时间"
                range-separator="-"
                type="datetimerange"
                value-format="YYYY-MM-DD HH:mm:ss"
                unlink-panels
            />
          </el-form-item>
        </el-col>

        <el-col :span="4">
          <el-form-item>
            <el-button icon="Search" type="primary" @click="getList">查询</el-button>
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>

      </div>
    </el-form>

    <vxe-table  style="margin-top: 10px"
                :data="tableData"
                :height="tableHeight"
                align="center"
                border
                :row-config="{isCurrent: true, isHover: true}"
    >
      <vxe-column title="序号" type="seq" width="60"></vxe-column>
      <vxe-column field="purchaseCode" width="200" title="云仓采购单号">
      </vxe-column>
      <vxe-column field="purchaseOrderCode" width="200" title="erp采购单号">
      </vxe-column>
      <vxe-column field="status"  width="100" title="退货状态">
        <template v-slot="{row}">
          {{ returnDictLabel(erp_qc_return_status, row.status) }}
        </template>
      </vxe-column>
      <vxe-column field="skuCode" width="200" title="SKU编码" ></vxe-column>
      <vxe-column field="skuName" width="220" title="商品名称" ></vxe-column>
      <vxe-column field="coverUrl"  width="180" title="商品图片">
        <template #default="{row}">
          <ImagePreview v-if="row.coverUrl" :width="150" :height="50" :src="row.coverUrl" ></ImagePreview>
        </template>
      </vxe-column>
      <vxe-column field="companyName"  width="150" title="公司名称" ></vxe-column>
      <vxe-column field="warehouseName" width="150" title="仓库名称"></vxe-column>
      <vxe-column field="returnNum" width="80" title="退货数量" ></vxe-column>
      <vxe-column field="delivery" width="100" title="退货方式" ></vxe-column>
      <vxe-column field="qcByName" width="100" title="质检人" ></vxe-column>
      <vxe-column field="qcTime" width="150" title="质检时间" ></vxe-column>

    </vxe-table>
    <pagination
        v-show="total > 0"
        v-model:limit="queryParams.pageSize"
        v-model:page="queryParams.pageNum"
        :total="total"
        @pagination="getList"
    />
  </div>
</template>

<script setup>
import {getCurrentInstance, onMounted, ref} from "vue";
import {nextTick} from "@vue/runtime-core";
import ImagePreview from "@/components/ImagePreview/index.vue";
import {getQcReturnlist} from "@/api/scApi";

const {proxy} = getCurrentInstance();
const { erp_qc_return_status } = proxy.useDict("erp_qc_return_status");
let loading=ref(false)
const queryParams=ref({
  pageNum: 1,
  pageSize: 10,
})
let timeData=ref([])
const title =ref('')
const tableData=ref([])
const total=ref(0)

const resetQuery = () => {
  timeData.value=[]
  queryParams.value={
    pageNum: 1,
    pageSize: 10,
  }
  getList();
};
function getList(){
  loading.value=true
  queryParams.value.startTime=timeData.value[0]
  queryParams.value.endTime=timeData.value[1]
  let params={
    pageNum:queryParams.value.pageNum,
    pageSize:queryParams.value.pageSize,
    param:queryParams.value
  }
  getQcReturnlist(params).then(res=>{
    if(res.code===200){
      tableData.value =res.data
      total.value =res.total
    }
  }).finally(()=>{
    loading.value =false
  })
}

let tableHeight = ref(0);
onMounted(() => {
  nextTick(() => {
    tableHeight.value = window.innerHeight - 360;
  })
  window.onresize = () => {
    tableHeight.value = document.body.scrollHeight - 360;
  }
  getList()
})
</script>

<style scoped lang="scss">


</style>